package ${JarName};

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.*;
import com.szholly.data.general.metadata.IBaseTable;

/**
 * ${tableName}
 */
@Component("${tableName}")
public class ${tableName}Table extends InterceptorTableBase  implements IBaseTable{

	public final static String TABLE_NAME = "${tableRealName}";
	
	/**
	 * single ref
	 */
	public static ${tableName}Table getSingleRef() {
		return (${tableName}Table) SpringBeanFactory.getBean("${tableName}");
	}

	@Override
	public String getMetadataTableName() {
		return TABLE_NAME;
	}

	@Override
	public String getMetadataTableAliasName() {
		return "${tableName}";
	}

	private HashMap<String, Field> fields;

	@Override
	protected HashMap<String, Field> fields() {
		if (fields == null) {
			fields = new HashMap<String, Field>();

			Field itemField = null;
			<#if hasGUID="0">
			itemField = new Field();
			itemField.setFieldName(RowBase.FIELD_GUID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(1);
			itemField.setFieldAliasName("GUID");
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			</#if>
			
			<#assign x = 5>
			<#list tableFields as item>
			itemField = new Field();
			itemField.setFieldName(${tableName}Row.FIELD_${item.fieldName});
			itemField.setDataType(GlobalDataType.${item.dataType});
			itemField.setFieldID(${x});
			itemField.setFieldAliasName("${item.fieldAliasName}");
			itemField.setAllowNull(${item.isNullable});
			<#if item.maxLen??>
			itemField.setMaxLen(${item.maxLen!0});
			</#if>
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			<#assign x = x + 1>
			</#list> 
		}
		return fields;
	}

	@Override
	public String getTableGroup() {
		return "${tableName}";
	}
}